package com.ha8.netease.views.team.login
{
	import com.ha8.netease.models.WeiboProxy;
	import com.rogo.mvc.sub.mediator.Mediator;
	
	import flash.events.MouseEvent;
	
	/**
	 * 登录页面视图代理
	 * 
	 * @author rogo
	 */	
	public class LoginViewMediator extends Mediator
	{
		public function LoginViewMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		public static const NAME:String = 'loginViewMediator';
		
		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override public function onRegister():void
		{
			view.getOauth.addEventListener(MouseEvent.CLICK, getOauth_clickHandler);
			view.loginBtn.addEventListener(MouseEvent.CLICK, loginBtn_clickHandler);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function get view():LoginView
		{
			return viewComponent as LoginView;
		}
		
		public function get proxy():WeiboProxy
		{
			return facade.retrieveProxy(WeiboProxy.NAME) as WeiboProxy;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//--------------------------------------------------------------------------
		
		private function getOauth_clickHandler(e:MouseEvent):void
		{
			// 获取授权码
			proxy.oauth();
		}
		
		private function loginBtn_clickHandler(e:MouseEvent):void
		{
			// 使用授权码登录
			proxy.login(view.pinInput.text);
		}
	}
}